import type { User, UserInfo, Patient, CodeType } from '@/types/user'
import { request } from '@/utils/request'

export const bindMobile = (data: {
  mobile: string
  code: string
  openId: string
}) => request<User>({ url: '/login/binding', method: 'POST', data })

export const loginByQQ = (openId: string) =>
  request<User>({
    url: '/login/thirdparty',
    method: 'POST',
    data: { openId, source: 'qq' },
  })

// 查询患者详情
export const getPatientDetail = (id: string) =>
  request<Patient>({ url: `/patient/info/${id}` })

// 删除患者信息
export const delPatient = (id: string) =>
  request({
    method: 'DELETE',
    url: `/patient/del/${id}`,
  })

// 编辑患者信息
export const editPatient = (patient: Patient) =>
  request({
    method: 'PUT',
    url: '/patient/update',
    data: patient,
  })

// 添加患者信息
export const addPatient = (patient: Patient) =>
  request({ method: 'POST', url: '/patient/add', data: patient })

// 获患者信息列表
export const getPatientList = () =>
  request<Patient[]>({ url: '/patient/mylist' })

// 获取用户信息
export const getUserInfo = () => request<UserInfo>({ url: '/patient/myUser' })

// 短信登录
export const loginByMobile = (mobile: string, code: string) =>
  request<User>({ method: 'POST', url: '/login', data: { mobile, code } })

// 发送验证码
export const sendMobileCode = (mobile: string, type: CodeType) =>
  request({
    url: '/code',
    data: {
      mobile,
      type,
    },
  })

// 密码登录
export const loginByPassword = (mobile: string, password: string) =>
  request<User>({
    method: 'POST',
    url: '/login/password',
    data: {
      mobile,
      password,
    },
  })
